<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Description: 社区
 *
 * @author      Eden
 * @datetime    2016/12/10 22:46
 * @copyright   Beijing CmsTop Technology Co.,Ltd.
 */

class Lists extends ADM_Controller
{
    const PAGE_SIZE = 20;

    /**
     * 初始化
     */
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $this->load->view(parent::TMP_DIR . '/bbs/index.html');
    }

    public function getLists()
    {
        $send['state'] = false;
        do {
            $page = $this->input->get('page');
            $page = intval($page) > 0 ? intval($page) : 1;
            $offset = ($page - 1) * self::PAGE_SIZE;
            $type = $this->input->get('type');

            if(!empty($type) && !in_array($type, array('all', 'text', 'mixed'))) {
                $send['error'] = '参数错误';
                break;
            }

            $this->load->model('admin/bbs/Index_Model', 'index');
            $res = $this->index->getLists($type, $offset, self::PAGE_SIZE);

            $send['state'] = true;
            $send['data'] = $res;

        } while(false);
        $this->output->send($send);
    }

    /**
     * 删除帖子
     */
    public function remove()
    {
        $send['state'] = false;
        do {
            $bbsId = $this->input->get('bbsId');
            if (empty($bbsId)) {
                $send['error'] = '参数错误';
                break;
            }

            $this->load->model('admin/bbs/Index_Model', 'bbs');
            $res = $this->bbs->remove($bbsId);
            if (!$res) {
                $error = $this->bbs->getError();
                $send['error'] = !empty($error) ? $error : '删除失败';
                break;
            }

            $send['state'] = true;
        } while(false);
        $this->output->send($send);
    }




}
